home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0079_Opening Many Files at a time.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  107 lines

  1. {
  2. Here's a unit that will let you open more than the default
  3. maximum number of files (up to about 200, FILES statement
  4. in CONFIG.SYS permitting) :
  5. }
  6.  
  7. {$o-,f-,r-,s-}
  8. {$IfDef DPMI}
  9.      {$c Moveable PreLoad Discardable}
  10. {$EndIf}
  11.  
  12. Unit ExtHandl ;
  13.  
  14. Interface
  15.  
  16. {$IfNDef DPMI}
  17. Procedure DOSRealloc(p : Pointer) ;
  18. {$EndIf}
  19.  
  20. Implementation
  21.  
  22. {$IfNDef DPMI}
  23. Procedure DOSRealloc(p : Pointer) ; Assembler ;
  24. { This procedures changes the size of the memory block allocated to the
  25.   program. It proceeds the same way than the SetMemTop procedure of the
  26.   Memory unit does. }
  27. Asm
  28.      Mov  BX, Word Ptr [p]                   { offset }
  29.      Add  BX, $0f
  30.      Mov  CL, 4
  31.      ShR  BX, CL
  32.      Add  BX, Word Ptr [p+2]                 { segment }
  33.      Mov  AX, PrefixSeg
  34.      Sub  BX, AX
  35.      Mov  ES, AX
  36.      { ES contains the program's PSP, BX is the new number of paragraphs
  37.        of the memory block. }
  38.      Mov  AH, $4a                            { Modify memory allocation }
  39.      Int  $21
  40. End ;
  41. {$EndIf}
  42.  
  43. Const
  44.      FreeParas      = 1024 Div 16 ;     { We're going to make sure DOS     }
  45.                                         { still has some RAM               }
  46.      Reallocating   = 1 ;
  47.      TPLacksRAM     = 2 ;
  48.      GettingHandles = 3 ;
  49.  
  50. Procedure PrintError(ErrNo : Word ; Location : Word) ;
  51. Begin
  52.      WriteLn(ParamStr(0)) ;
  53.      WriteLn('ExtHandl : Startup error #', ErrNo, ', location=', Location) ;
  54.      WriteLn('MaxAvail=', MaxAvail) ;
  55.      Write('[Enter] pour continuer...') ;
  56.      ReadLn ;
  57. End ;
  58.  
  59. Begin
  60.      { This initialisation code makes sure DOS is still able to assume
  61.        memory allocation requests that are likely to occur (whether by
  62.        Spawno or a "Set Handle Count" request).
  63.        This allows the main program to use whatever $m statement it needs. }
  64.      Asm
  65. {$IfNDef DPMI}
  66.           Mov  AH, $48                  { Allocate memory }
  67.           Mov  BX, $ffff                { More than DOS can give us }
  68.           Int  $21
  69.           Cmp  BX, FreeParas            { BX contains avail paragraphs }
  70.           JNC  @DOSHasEnough
  71.           { Let's check that the heap contains more than needed bytes }
  72.           Mov  AX, Word Ptr [HeapPtr+2]
  73.           Add  AX, FreeParas
  74.           Cmp  AX, Word Ptr [HeapEnd+2]
  75.           JNC  @NotEnoughRAM            { Actually, TP hasn't enough }
  76.           Sub  Word Ptr [HeapEnd+2], FreeParas
  77.           Push Word Ptr [HeapEnd+2]
  78.           Push Word Ptr [HeapEnd]
  79.           Call DOSRealloc
  80.           JNC  @DOSHasEnough
  81.           Push AX
  82.           Mov  AX, Reallocating
  83.           Push AX
  84.           Call PrintError
  85.           Jmp  #DOSHasEnough
  86.      @NotEnoughRAM:
  87.           XOr  AX, AX
  88.           Push AX
  89.           Mov  AX, TPLacksRAM
  90.           Push AX
  91.           Call PrintError
  92.      @DOSHasEnough:
  93. {$EndIf}
  94.           { Augmentation du nombre de handles disponibles }
  95.           Mov  AH, $67                  { Extend handles }
  96.           Mov  BX, 199                  { Gi'me 2 hundreds of 'em }
  97.           Int  $21
  98.           JNC  @PasDErreur              { Si CF=1, erreur }
  99.           Push AX
  100.           Mov  AX, GettingHandles
  101.           Push AX
  102.           Call PrintError
  103.      @PasDErreur:
  104.      End ;
  105. End.
  106.  
  107.